package SecondeStage.Collection.Map;

import java.util.*;

@SuppressWarnings({"all"})
public class MapFor {
    public static void main(String[] args) {
        // Map遍历方式
        Map map =new HashMap();
        map.put("邓超",new Book("",100));
        map.put("邓超","孙俪");
        map.put("王宝强","马蓉");
        map.put("宋喆","马蓉");
        map.put("刘玲波",null);
        map.put(null,"刘亦菲");
        map.put("鹿晗","关晓彤");
        // 第一组:先取出所有的key，通过key取出对应的value
        Set keyset = map.keySet();
        // 1.增强for循环
        for (Object key :keyset) {
            System.out.println(key+" "+map.get(key));
        }
        System.out.println("--------------");
        // 2. 迭代器
        Iterator iterator = keyset.iterator();
        while (iterator.hasNext()) {
            Object key =  iterator.next();
            System.out.println(key+" "+map.get(key));
        }
        System.out.println("--------------");

        // 第二组: 把所有的value取出
        Collection values = map.values();
        // 3. 增强for
        for (Object value :values) {
            System.out.println(value);
        }
        System.out.println("--------------");
        // 4. 迭代器
        Iterator iterator2 = values.iterator();
        while (iterator2.hasNext()) {
            Object value =  iterator2.next();
            System.out.println(value);
        }
        System.out.println("--------------");

        // 第三组: 通过EntrySet获取k-v
        Set entrySet = map.entrySet();
        // 5.增强for
        for (Object entry :entrySet) {
            // 将entry转换成 Map.Entry
            Map.Entry m =(Map.Entry)entry;
            System.out.println(m.getKey()+" "+m.getValue());
        }
        System.out.println("--------------");
        // 6.迭代器
        Iterator iterator3 = entrySet.iterator();
        while (iterator3.hasNext()) {
            Map.Entry m =  (Map.Entry)iterator3.next();
            System.out.println(m.getKey()+" "+m.getValue());
        }
    }
}
